********************************************************************************
**  TITLE:      us2016_taps_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       2016								                          **
**  DATE:	    October 2022 						                          **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us2016_taps_contact_networks", replace

* Import monthly datasets for interview dates

import spss using "S52 - TAPS - March 2016", case(lower) clear
keep wustlid tm_finishs52
rename tm_finishs52 finishtimes52
save "S52 - TAPS - March 2016.dta", replace

import spss using "S56 - TAPS - July 2016-1", case(lower) clear
keep wustlid tm_finishs56
rename tm_finishs56 finishtimes56
save "S56 - TAPS - July 2016-1.dta", replace

* Open the dataset

use "2016.dta", clear

* Merge with demographic profile dataset

merge 1:1 wustlid using "Complete Profiles Sorted.dta"

drop _merge

* Merge with interview dates (finish time)

merge 1:1 wustlid using "S52 - TAPS - March 2016.dta"

drop _merge

merge 1:1 wustlid using "S56 - TAPS - July 2016-1.dta"

drop _merge


***************************
** INDEPENDENT VARIABLES **
***************************

* Time (presidential election)

gen surveydate = dofc(finishtimes56)

format %tdMon_DD,_CCYY surveydate

gen edate = 20161108

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Time (Democratic primary election)

gen psurveydate = dofc(finishtimes52)

format %tdMon_DD,_CCYY psurveydate

gen ddate = 20160728

gen demdate=date(string(ddate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY demdate

gen dtime = demdate - psurveydate

* Time (Republican primary election)

gen rdate = 20160719

gen repdate=date(string(rdate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY repdate

gen rtime = repdate - psurveydate

* Gender

gen male = gendersp

recode male -1=. 2=0

* Age

gen age = agesp

replace age = . if age < 17

* Education

gen education = ppeducat

* Interest for politics

gen interest = interestpolsp

recode interest -1=.

replace interest = 5 - interest

* Party identification

gen pidstatus_whole = PARTYID1SP

recode pidstatus_whole (-1=.)

recode pidstatus_whole 2=3 3=2 4=2

label define pidstatus 1 "Loser PID" 2 "No PID/Other" 3 "Winner PID" 
label values pidstatus_whole pidstatus

* Party identification scale

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & PARTYID2SP == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & PARTYID2SP == 2
replace pidscale_whole = 3 if pidstatus_whole == 2
replace pidscale_whole = 4 if pidstatus_whole == 3 & PARTYID2SP == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & PARTYID2SP == 1

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "No PID/Other" 4 "Weak winner PID" 5 "Strong winner PID" 
label values pidscale_whole pidscale

* Democratic primary vote

gen demvote = DEMNOVB15S52

recode demvote 1=. 2=1 3=0 5=0

label define primarystatus 0 "Loser vote" 1 "Winner vote" 
label values demvote primarystatus

* Republican primary vote

gen repvote = REPNOV15S52

recode repvote 1=. 3=0 4=0 5=0 6=1 7=0 8=0 9=.

label values repvote primarystatus

* News attentiveness

gen news_s51 = VOTENEWSS51

recode news_s51 1=. 5=1 4=2 2=4

gen news_s53 = VOTENEWSS53

recode news_s53 1=. 5=1 4=2 2=4

gen news_s57 = VOTENEWSS57

recode news_s57 1=. 5=1 4=2 2=4

* Political discussion with friends, family, or other acquaintances (primaries)

gen discussion1_s53 = POLPART2S53

recode discussion1_s53 1=. 2=0 3=1 4=2 5=3 6=4 7=5 8=6 9=7

* Political discussion with neighbors (primaries)

gen discussion2_s53 = POLPART5S53

recode discussion2_s53 1=. 2=0 3=1 4=2 5=3 6=4 7=5 8=6 9=7

* Political discussion frequency (primaries)

egen discussion_s53 = rowmax(discussion1_s53 discussion2_s53)

gen discussion_s53_3pts = 0 if discussion_s53 < 2 & discussion_s53!=.
replace discussion_s53_3pts = 1 if discussion_s53 >= 2 & discussion_s53 < 4 & discussion_s53!=.
replace discussion_s53_3pts = 2 if discussion_s53 >= 4 & discussion_s53!=.

* Political discussion with friends, family, or other acquaintances (presidential election)

gen discussion1_s57 = POLPART2S57

recode discussion1_s57 1=. 2=0 3=1 4=2 5=3 6=4 7=5 8=6 9=7

* Political discussion with neighbors (presidential election)

gen discussion2_s57 = POLPART5S57

recode discussion2_s57 1=. 2=0 3=1 4=2 5=3 6=4 7=5 8=6 9=7

* Political discussion frequency (presidential election)

egen discussion_s57 = rowmax(discussion1_s57 discussion2_s57)

gen discussion_s57_3pts = 0 if discussion_s57 < 2 & discussion_s57!=.
replace discussion_s57_3pts = 1 if discussion_s57 >= 2 & discussion_s57 < 4 & discussion_s57!=.
replace discussion_s57_3pts = 2 if discussion_s57 >= 4 & discussion_s57!=.

* Size (primaries)

gen size_s53 = POLPART1S53

recode size_s53 1=. 2=0 3=1 4=2 5=3 6=4

gen size_s53_3pts = size_s53
recode size_s53_3pts 1=0 2=1 3=2 4=2

* Size (presidential election)

gen size_s57 = POLPART1S57

recode size_s57 1=. 2=0 3=1 4=2 5=3 6=4

gen size_s57_3pts = size_s57
recode size_s57_3pts 1=0 2=1 3=2 4=2

* Which party holds a majority of seats in the U.S. House of Representatives in Washington - Correct answer (Republican) = 1, Incorrect answer = 0

gen house = POLKNOW1S55

recode house 1=. 2=0 3=1 4=0 5=0

* How many votes are required in Congress to override a presidential veto - Correct answer (a two-thirds majority of both houses of Congress) = 1, Incorrect answer = 0

gen veto = POLKNOW2S55

recode veto 1=. 2=0 3=0 4=1 5=0 6=0

* How long is one term for a member of the U.S. Senate? - Correct answer (six years) = 1, Incorrect answer = 0

gen snterm = POLKNOW3S55

recode snterm 1=. 2=0 3=0 4=1 5=0 6=0

* The ability of a minority of senators to prevent a vote on a bill is known as... - Correct answer (filibuster) = 1, Incorrect answer = 0

gen filibuster = POLKNOW5S55

recode filibuster 1=. 2=0 3=1 4=0 5=0 6=0

* Who is the Vice President of the United States - Correct answer (Joseph Biden) = 1, Incorrect answer = 0

gen vicepresident = POLKNOW6S55

recode vicepresident 1=. 2=0 3=0 4=1 5=0 6=0

* A president may serve... - Correct answer (two terms) = 1, Incorrect answer = 0

gen prterm = POLKNOW7S55

recode prterm 1=. 2=0 3=1 4=0 5=0 6=0

* Members of the U.S. Supreme Court serve... - Correct answer (life terms) = 1, Incorrect answer = 0

gen scterm = POLKNOW12S55

recode scterm 1=. 2=0 3=0 4=1 5=0 6=0

* Who is Chief Justice of the United States Supreme Court - Correct answer (John Roberts) = 1, Incorrect answer = 0

gen chief = POLKNOW13S55

recode chief 1=. 2=1 3=0 4=0 5=0 6=0

* Social Security is... - Correct answer (the benefit program for senior citizens) = 1, Incorrect answer = 0

gen socialsecurity = POLKNOW17S55

recode socialsecurity 1=. 2=1 3=0 4=0 5=0 6=0

* On which of the following federal programs is the most money spent each year - Correct answer (Medicare) = 1, Incorrect answer = 0

gen mostmoney = POLKNOW18S55

recode mostmoney 1=. 2=0 3=1 4=0 5=0 6=0

* A system of government in which power is divided between the central government and state or regional governments is called... - Correct answer (a federation) = 1, Incorrect answer = 0

gen federation = POLKNOW21S55

recode federation 1=. 2=0 3=1 4=0 5=0 6=0

* In modern American politics, which of the following groups generally wants lower taxes and smaller government - Correct answer (conservatives) = 1, Incorrect answer = 0

gen lowtaxes = POLKNOW22S55

recode lowtaxes 1=. 2=0 3=0 4=1 5=0 6=0

* The Secretary of Defense is appointed by the... - Correct answer (President) = 1, Incorrect answer = 0

gen appoint = POLKNOW23S55

recode appoint 1=. 2=1 3=0 4=0 5=0 6=0

* President Obama is affiliated with what political party? - Correct answer (Democratic Party) = 1, Incorrect answer = 0

gen obama = POLKNOW24S55

recode obama 1=. 2=0 3=0 4=1 5=0 6=0

* The Office of Management and Budget... - Correct answer (was originally called the Bureau of the Budget) = 1, Incorrect answer = 0

gen omb = POLKNOW25S55

recode omb 1=. 2=0 3=0 4=1 5=0 6=0

* Political knowledge index

gen knowledge = house + veto + snterm + filibuster + vicepresident + prterm + scterm + chief + socialsecurity + mostmoney + federation + lowtaxes + appoint + obama + omb


***************************************
** REPUBLICAN PRIMARIES EXPECTATIONS **
***************************************

* Forecasts

gen forecast_repprimaries = REPWINS52

recode forecast_repprimaries 1=. 

* Identify correct forecasts

gen correct_repprimaries_d = 0 if forecast_repprimaries!=6 & forecast_repprimaries!=.
replace correct_repprimaries_d = 1 if forecast_repprimaries == 6


***************************************
** DEMOCRATIC PRIMARIES EXPECTATIONS **
***************************************

* Forecasts

gen forecast_demprimaries = DEMWINS52

recode forecast_demprimaries 1=. 

* Identify correct forecasts

gen correct_demprimaries_d = 0 if forecast_demprimaries!=2 & forecast_demprimaries!=.
replace correct_demprimaries_d = 1 if forecast_demprimaries == 2


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts

gen forecast_whole = WINS56

recode forecast_whole 1=. 

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=2 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 2


**********
** SAVE **
**********

save "us2016_taps.dta", replace


*****************************************
** MAIN ANALYSES: REPUBLICAN PRIMARIES **
*****************************************

* Regression analysis and percentage of correct and incorrect forecasts (Democratic primaries)

logistic correct_repprimaries_d discussion_s53 size_s53 i.repvote interest news_s51 age i.male education rtime
estimates table, star(.05 .01 .001)

tab correct_repprimaries_d if e(sample) == 1


**********************************************
** SUMMARY STATISTICS: REPUBLICAN PRIMARIES **
**********************************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_repprimaries_d "Republican nominee (DV)"
label variable correct_demprimaries_d "Democratic nominee (DV)"
label variable discussion_s53 "Discussion"
label variable size_s53 "Network size"
label variable pidscale_whole "National PID"
label variable repvote "Republican primary vote"
label variable demvote "Democratic primary vote"
label variable interest "Interest"
label variable news_s51 "News attentiveness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable dtime "Time of interview"
label variable rtime "Time of interview"

estpost tabstat correct_repprimaries_d discussion_s53 size_s53 repvote interest news_s51 age male education rtime if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2016_taps_summary_repprimaries.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2016 Republican presidential primaries (TAPS), national level") replace


*****************************************
** MAIN ANALYSES: DEMOCRATIC PRIMARIES **
*****************************************

* Regression analysis and percentage of correct and incorrect forecasts (Democratic primaries)

logistic correct_demprimaries_d discussion_s53 size_s53 i.demvote interest news_s51 age i.male education dtime
estimates table, star(.05 .01 .001)

tab correct_demprimaries_d if e(sample) == 1


**********************************************
** SUMMARY STATISTICS: DEMOCRATIC PRIMARIES **
**********************************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_repprimaries_d "Republican nominee (DV)"
label variable correct_demprimaries_d "Democratic nominee (DV)"
label variable discussion_s53 "Discussion"
label variable size_s53 "Network size"
label variable pidscale_whole "National PID"
label variable repvote "Republican primary vote"
label variable demvote "Democratic primary vote"
label variable interest "Interest"
label variable news_s51 "News attentiveness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable dtime "Time of interview"
label variable rtime "Time of interview"

estpost tabstat correct_demprimaries_d discussion_s53 size_s53 demvote interest news_s51 age male education dtime if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2016_taps_summary_demprimaries.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2016 Democratic presidential primaries (TAPS), national level") replace


******************************************
** MAIN ANALYSES: PRESIDENTIAL ELECTION **
******************************************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion_s57 size_s57 pidscale_whole interest news_s57 age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


***********************************************
** SUMMARY STATISTICS: PRESIDENTIAL ELECTION **
***********************************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_repprimaries_d "Republican nominee (DV)"
label variable correct_demprimaries_d "Democratic nominee (DV)"
label variable discussion_s57 "Discussion"
label variable size_s57 "Network size"
label variable pidscale_whole "National PID"
label variable repvote "Republican primary vote"
label variable demvote "Democratic primary vote"
label variable interest "Interest"
label variable news_s57 "News attentiveness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable dtime "Time of interview"
label variable rtime "Time of interview"

estpost tabstat correct_whole_d discussion_s57 size_s57 pidscale_whole interest news_s57 age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2016_taps_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2016 American presidential election (TAPS), national level") replace

eststo clear

log close